package com.qyer.search.model;

import static com.qyer.commons.utils.CommonUtils.cast2Int;
import static com.qyer.commons.utils.CommonUtils.cast2String;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.collections4.MapUtils;

import java.util.Map;

/**
 * User: Z J Wu Date: 2016/01/05 Time: 20:48 Package: com.qyer.search.model
 */
public abstract class QyerPlace {

  public static final String FIELD_ID = "id";

  @JsonProperty
  protected int id;

  @JsonProperty
  protected String placeName;

  public QyerPlace() {
  }

  public QyerPlace(int id, String placeName) {
    this.id = id;
    this.placeName = placeName;
  }

  public static Country buildCountry(Map<String, Object> dataMap) {
    if (MapUtils.isEmpty(dataMap)) {
      return null;
    }
    return new Country(cast2Int(dataMap.get(FIELD_ID)),
                       cast2String(dataMap.get(Country.FIELD_NAME)));
  }

  public static City buildCity(Map<String, Object> dataMap) {
    if (MapUtils.isEmpty(dataMap)) {
      return null;
    }
    return new City(cast2Int(dataMap.get(FIELD_ID)), cast2String(dataMap.get(City.FIELD_NAME)));
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getPlaceName() {
    return placeName;
  }

  public void setPlaceName(String placeName) {
    this.placeName = placeName;
  }
}
